<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /**
     * 内置函数：String Array Math Date
    */
   //Math.round() 四舍五入
   var result1 = Math.round(9.8);
   console.log(result1);
    //保留一位小数，四舍五入
    var num = 2.16;
    num = num*10;
    var result2 = Math.round(num);
    result2 = result2/10;
    console.log(result2);

    //Math.floor() 向下取整 Math.ceil() 向上取整
    var result3 = Math.floor(1.6);
    var result4 = Math.ceil(1.3);
    console.log(result3,result4);

    /**
     * Math.random() 生成0-1的随机小数，包含0不包含1
     * 变换随机值的范围，可以乘以对应的值
    */
    var result = Math.random();
    console.log(result);

    var arr = ["hello", "world", "java", "script"];
    var index = result*arr.length;
    index = parseInt(index);
    console.log(index);
    console.log(arr[index]);

    //1-100  Math.random()
    var r = Math.random();
    //var result1 = r*100;//包含0，不包含100
    var result1 = parseInt(r*100+1);//1-100
    console.log(result1);

    //Math.max()最大值 Math.min()最小值
</script>
</html>